<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\library\Token;

class Artitem extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();
    }

    public function index(){
        echo 1;
    }

    public function artitem($item=0,$page=1){
        if($item=='0'){
            return $this->error('404');
            exit;
        }

        #获取位置
        $url = $this->geturl($item);
        //dump($url);
        if(empty($url['name'])){
            return $this->error('404');
            exit;
        }

        #获取数目
        $count = ceil(count(model('Getitem')->itemAll($url['id']))/10);
        $end=$count<10?$count:10;

        #获取分类文章
        $limit=($page-1)*10;
        $items = model('Getitem')->item($url['id'],$limit.',10');

        #推荐信息-10篇
        $tjxx = model('Getitem')->itemRand(10);

        #最新资讯-8篇
        $zxzx = model('Getitem')->itemA('updatetime','desc',10);

        #热门内容-8篇
        $rmnr = model('Getitem')->itemA('views','desc',10);


        $this->assign([
            'web_title' =>  '湖北专升本网 - '.$url['pname'].' - '.$url['name'],
            'web_keywords'  =>  '湖北专升本网 - '.$url['pname'].' - '.$url['name'],
            'web_description'   =>  '湖北专升本网 - '.$url['pname'].' - '.$url['name'],
            'page'  =>  $page,
            'url'   =>  $url,
            'items' =>  $items,
            'tjxx'  =>  $tjxx,
            'count' =>  $count,
            'end'   =>  $end,
            'zxzx'  =>  $zxzx,
            'rmnr'  =>  $rmnr
        ]);
        return $this->fetch();
    }

    protected function geturl($item){
        $res = model('Getitem')->getcateid($item);
        $ret['name'] = $res['name'];
        $ret['nick'] = $item;
        $ret['id']  =   $res['id'];
        $res = model('Getitem')->getcate($res['pid']);
        $ret['pname'] = $res['name'];
        $ret['pnick'] = $res['nickname'];
        return $ret;
    }

    //自考专业一览表

    public function zkzy(){
        
        //专科
        $zy_zk = model('Getyx')->itemzkzy(1);

        //本科
        $zy_bk = model('Getyx')->itemzkzy(2);

        $this -> assign([
            'web_title'     =>  '湖北自考专业一览表',
            'web_keywords'  =>  '湖北自考专业',
            'web_description'   =>  '湖北自考专业计划-专业课程',
            'zy_zk' =>  $zy_zk,
            'zy_bk' =>  $zy_bk,
        ]);
        

        return $this->fetch();
    }

}